New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sodium-encryption

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sodium-encryption

Sodium encryption that works in node and in the browser

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

sodium-encryption

Sodium encryption that works in node and in the browser

npm install sodium-encryption

build status

Usage

var encryption = require('sodium-encryption')

var key = encryption.key()
var nonce = encryption.nonce()
var message = Buffer('a message')

var box = encryption.encrypt(message, nonce, key)

console.log('encrypted message is:', box)
console.log('decrypted message is:', encryption.decrypt(box, nonce, key))

API

key = encryption.key()

Generate a secret key. Returns a 32 byte buffer.

nonce = encryption.nonce()

Generate a nonce. Returns a 24 byte buffer. A nonce can be public and you should use a new one everytime you use a key.

box = encryption.encrypt(message, nonce, key)

Encrypts a message.

message = encryption.decrypt(box, nonce, key)

Decrypt a message. Returns null is the message cannot be decrypted.

keys = encryption.scalarMultiplicationKeyPair([secretKey])

Generate a key pair to be used for scalar multiplication. If you don't pass in a secret key, one will be generated for you. Returns a key pair consisting of a secret key and a public key.

{
  secretKey: <Buffer>,
  publicKey: <Buffer>
}
sharedKey = encryption.scalarMultiplication(secretKey, otherPublicKey)

Generate a shared key based on a remote public scalar multiplication key and your own secret key. Returns the same shared key if called with corresponding secret and public key

var keys = encryption.scalarMultiplicationKeyPair()
var otherKeys = encryption.scalarMultiplicationKeyPair()

console.log('shared key', encryption.scalarMultiplication(keys.secretKey, otherKeys.publicKey))
console.log('shared key', encryption.scalarMultiplication(otherKeys.secretKey, keys.publicKey))

License

MIT

FAQs

Package last updated on 17 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc